/**
 * Created by wangfei on 2017/6/15.
 */

/**
 *
 *
 * */
var Ajax = {
    post: function(url, data, callback, errCallback) {
        $.ajax({
            type: 'POST',
            url: config.host + url,
            dataType: 'json',
			data: data,
            //data: JSON.stringify(data),
            //contentType: "application/json; charset=utf-8",
            success: callback,
            error: function(err){
                if(errCallback) errCallback(err);
            }
        })
    },
    get: function(url, data, callback, errCallback) {
        $.ajax({
            type: 'get',
            url: config.host + url,
            dataType:'json',
            data:data,
            contentType: "application/json; charset=utf-8",
			processData: false,
			contentType: false,
            success: callback,
            error: function(err){
                if(errCallback) errCallback(err);
            }
        })
    },
    sendImg: function(url, data, callback, errCallback){
        $.ajax({
            type: 'post',
            url: config.host + url,
            dataType: 'json',
            data: data,
            processData: false,
            contentType: false,
            success: callback,
            error: function(err){
                if(errCallback) errCallback(err);
            }
        })
    }
}
window.Ajax = Ajax;

(function(win, $){

    win.Api = {
		//上传图片
		sendImg: function(data, callback, errCallback) {
			Ajax.sendImg('/ware/sendImg', data, callback, errCallback);
		},
        //登录
        login: function(data, callback){
            Ajax.post('/login', data, callback);
        },
        //获取验证码
        verifyCode: function(){
            return config.host+ '/verifyCode?' + parseInt(Math.random()*1e7);
        },
		//退出
		logout: function(callback) {
			Ajax.post('/logout', null, callback);
		},
		//首页
		home: function(callback) {
			Ajax.post('/home', null, callback);
		},
		//商品编辑分页列表
		wareEditPage: function(data, callback) {
			Ajax.post('/ware/edit/page', data, callback);
		},
		//待售商品分页列表
		wareForSalePage: function(data, callback) {
			Ajax.post('/ware/forSale/page', data, callback);
		},
		//在售商品分页列表
		wareOnSalePage: function(data, callback) {
			Ajax.post('/ware/onSale/page', data, callback);
		},
		//商品类别列表
		wareCategoryList: function(callback) {
			Ajax.post('/ware/category/list', null, callback);
		},
		//商品品牌列表
		wareBrandList: function(callback) {
			Ajax.post('/ware/brand/list', null, callback);
		},
		//销售站点列表
		supplierSiteList: function(callback) {
			Ajax.post('/supplier/site/list', null, callback);
		},
		//区域地址省列表
		regionProvinceList: function(callback) {
			Ajax.post('/region/province/list', null, callback);
		},
		//区域地址市列表
		regionCityList: function(data, callback) {
			Ajax.post('/region/city/list', data, callback);
		},
		//获取商品ID
		wareGetId: function(callback) {
			Ajax.post('/ware/getId', null, callback);
		},
		//商品详情
		wareGet: function(data, callback) {
			Ajax.post('/ware/get', data, callback);
		},
		//商品新增草稿
		wareAddDrafts: function(data, callback) {
			Ajax.post('/ware/addDrafts', data, callback);
		},
		//商品修改草稿
		wareUpdateDrafts: function(data, callback) {
			Ajax.post('/ware/updateDrafts', data, callback);
		},
		//商品新增审核
		wareAddSubmit: function(data, callback) {
			Ajax.post('/ware/addSubmit', data, callback);
		},
		//商品修改审核
		wareUpdateSubmit: function(data, callback) {
			Ajax.post('/ware/updateSubmit', data, callback);
		},
		//单装单位列表
		wareUnitList: function(callback) {
			Ajax.post('/ware/unit/list', null, callback);
		},
		//商品上架
		wareOnSale: function(data, callback) {
			Ajax.post('/ware/onSale', data, callback);
		},
		//商品下架
		wareForSale: function(data, callback) {
			Ajax.post('/ware/forSale', data, callback);
		},
		//商品撤回
		wareDrafts: function(data, callback) {
			Ajax.post('/ware/drafts', data, callback);
		},
		//商品管理
		wareUpdate: function(data, callback) {
			Ajax.post('/ware/update', data, callback);
		},
		//商品管理（变更为草稿）
		wareUpdateToDrafts: function(data, callback) {
			Ajax.post('/ware/updateToDrafts', data, callback);
		},
		//根据商品货号获取erp商品信息
		wareErpGet: function(data, callback) {
			Ajax.post('/ware/erp/get', data, callback);
		},
		//待发货订单分页列表
		orderForSendPage: function(data, callback) {
			Ajax.post('/order/forSend/page', data, callback);
		},
		//订单分页列表
		orderPage: function(data, callback) {
			Ajax.post('/order/page', data, callback);
		},
		//导出子订单列表
		orderExcel: function(data, callback) {
			Ajax.post('/order/excel', data, callback);
		},
		//子订单详情
		orderGet: function(data, callback) {
			Ajax.post('/order/get', data, callback);
		},
		//子订单发货
		orderSend: function(data, callback) {
			Ajax.post('/order/send', data, callback);
		},
		//日销售统计分页列表
		reportDailysalePage: function(data, callback) {
			Ajax.post('/report/dailysale/page', data, callback);
		},
		//商品销售统计分页列表
		reportWaresalePage: function(data, callback) {
			Ajax.post('/report/waresale/page', data, callback);
		},
		//供应商账户信息
		supplierGet: function(callback) {
			Ajax.post('/supplier/get', null, callback);
		},
		//供应商账户修改密码
		supplierPwdUpdate: function(data, callback) {
			Ajax.post('/supplier/pwd/update', data, callback);
		},
		//获取是否显示ERP
		supplierErp: function(callback) {
			Ajax.post('/supplier/erp', null, callback);
		},
		//删除商品图片
		wareDeleteImg: function(data, callback) {
			Ajax.post('/ware/deleteImg', data, callback);
		}
    }

})(
 window,
 jQuery
)